package com.novellotus.iov.carvice.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.novellotus.iov.carvice.R;
import com.novellotus.iov.carvice.bean.RxVehiclesType;
import com.novellotus.iov.carvice.utils.MyViewUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Rich on 2018/1/8.
 */

public class CarScreenAdapter extends RecyclerView.Adapter<CarScreenAdapter.CarItem> {

    private Context context;
    private List<RxVehiclesType> rxVehiclesTypeList;
    private CarScreenItemAdapter.CarScreenItemClickInterface carScreenItemClickInterface;
    private int carStatuePosition;
    private int carModelPosition;
    private boolean isOutGoging;

    public CarScreenAdapter(List<RxVehiclesType> rxVehiclesTypeList, CarScreenItemAdapter.CarScreenItemClickInterface carScreenItemClickInterface, int carStatuePosition, int carModelPosition,boolean isOutGoging) {
        this.rxVehiclesTypeList = rxVehiclesTypeList;
        this.carScreenItemClickInterface = carScreenItemClickInterface;
        this.carStatuePosition=carStatuePosition;
        this.carModelPosition=carModelPosition;
        this.isOutGoging=isOutGoging;
        if (this.rxVehiclesTypeList == null) {
            this.rxVehiclesTypeList = new ArrayList<>();
        }


    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public CarItem onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(context).inflate(R.layout.item_screen_layout, null);
        return new CarItem(view);

    }

    @Override
    public void onBindViewHolder(CarItem holder, int position) {

        if (position == 0) {
            holder.tv_tittle.setText("车辆状态");
            holder.recyclerView.setLayoutManager(MyViewUtils.gridLayoutManager(context, 3));
            holder.recyclerView.setAdapter(new CarScreenItemAdapter(0,carStatuePosition, rxVehiclesTypeList, carScreenItemClickInterface,isOutGoging));
        } else {
            holder.tv_tittle.setText("车辆型号");
            holder.recyclerView.setLayoutManager(MyViewUtils.getStaggeredGridLayoutManager(3));
            holder.recyclerView.setAdapter(new CarScreenItemAdapter(1,carModelPosition, rxVehiclesTypeList, carScreenItemClickInterface,isOutGoging));
        }


    }

    @Override
    public int getItemCount() {
        return 2;
    }


    class CarItem extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_tittle)
        TextView tv_tittle;
        @BindView(R.id.recyclerView)
        RecyclerView recyclerView;

        CarItem(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
